package com.ztsoft.user.controller.user;

import com.ztsoft.user.pojo.entity.user.SysRole;
import com.ztsoft.user.pojo.vo.user.SysRoleVo;
import com.ztsoft.user.service.user.SysRoleService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role")
@CrossOrigin("*")
@Api(tags = "角色控制层")
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;

    @GetMapping("/query")
    @ApiOperation(value = "查询全部可用角色", notes = "查询全部可用角色")
    public Result<Object> query() {
        return sysRoleService.queryRole();
    }

    @GetMapping("/queryByPage")
    @ApiOperation(value = "查询角色", notes = "带分页的条件查询")
    public Result<Object> queryByPage(SysRole role, Integer currentPage, Integer pageSize) {
        return sysRoleService.queryRoleByPage(role, currentPage, pageSize);
    }

    @GetMapping("/queryAllRoleName")
    @ApiOperation(value = "查询全部角色名称", notes = "查询全部角色名称")
    public Result<Object> queryAllRoleName() {
        return sysRoleService.queryAllRoleName();
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加角色", notes = "添加角色")
    public Result<Object> add(@RequestBody SysRoleVo sysRoleVo) {
        return sysRoleService.addRole(sysRoleVo);
    }

    @PutMapping("/updateInfo")
    @ApiOperation(value = "更新角色基本信息", notes = "更新角色基本信息")
    public Result<Object> updateInfo(@RequestBody SysRoleVo sysRoleVo) {
        return sysRoleService.updateRoleInfo(sysRoleVo);
    }

    @PutMapping("/updateRoleAndMenu")
    @ApiOperation(value = "更新角色与菜单关系", notes = "更新角色与菜单关系")
    public Result<Object> updateRoleAndMenu(@RequestBody SysRoleVo sysRoleVo) {
        return sysRoleService.updateRoleAndMenu(sysRoleVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除角色", notes = "按照id删除角色")
    public Result<Object> delete(@PathVariable("id") String id) {
        return sysRoleService.deleteRole(id);
    }

}